# -*- coding: utf-8 -*-
"""
BLL层 系统相关模块.
"""

import DAL.Class
import DAL.Question
import DAL.Papers
import DAL.Sys

#系统用户 - 登录验证
def _api_login(_request):
    objReturn = DAL.Sys._api_login(_request)
    return objReturn

def _api_get_api_help_json():
    """
    API接口帮助--返回API接口说明--JSON数组.

    编写：HenYan
    时间：2016年11月29日 09:34:54
    :return:
    """
    msghelp = []

    dal_class = dir(DAL.Class)
    for def_class in dal_class:
        apidic = {}
        if def_class[1:4] == "api":
            apidic.update({def_class:eval("DAL.Class." + def_class).__doc__})
            msghelp.append(apidic)

    dal_Question = dir(DAL.Question)
    for def_Question in dal_Question:
        apidic = {}
        if def_Question[1:4] == "api":
            apidic.update({def_Question: eval("DAL.Question." + def_Question).__doc__})
            msghelp.append(apidic)


    dal_Papers = dir(DAL.Papers)
    for def_Papers in dal_Papers:
        if def_Papers[1:4] == "api":
            apidic.update({def_Papers: eval("DAL.Papers." + def_Papers).__doc__})
            msghelp.append(apidic)

    return msghelp


def _api_get_api_help_html():
    """
    API接口帮助--返回API接口说明--HTML.

    :return:
    """
    html = ""
    try:
        html = """
        <html>
        	<head>
        		<title>API接口帮助文档</title>
        	</head>

        	<body>
            """
        dal_class = dir(DAL.Class)
        for def_class in dal_class:
            if def_class[1:4] == "api":
                # apidic.update({def_class: eval("DAL.Class." + def_class).__doc__})
                html += """
            <hr>
            <h1>""" + def_class + """<h1>
            <h3>""" + eval("DAL.Class." + def_class).__doc__.replace('\n', '<br>') + """<h3>
                    """

        dal_Question = dir(DAL.Question)
        for def_Question in dal_Question:
            if def_Question[1:4] == "api":
                # apidic.update({def_class: eval("DAL.Class." + def_class).__doc__})
                html += """
            <hr>
            <h1>""" + def_Question + """<h1>
            <h3>""" + eval("DAL.Question." + def_Question).__doc__.replace('\n', '<br>') + """<h3>
                    """

        dal_Papers = dir(DAL.Papers)
        for def_Papers in dal_Papers:
            if def_Papers[1:4] == "api":
                # apidic.update({def_class: eval("DAL.Class." + def_class).__doc__})
                html += """
            <hr>
            <h1>""" + def_Papers + """<h1>
            <h3>""" + eval("DAL.Papers." + def_Papers).__doc__.replace('\n', '<br>') + """<h3>
                    """

        dal_sys = dir(DAL.Sys)
        for def_sys in dal_sys:
            if def_sys[1:4] == "api":
                # apidic.update({def_class: eval("DAL.Class." + def_class).__doc__})
                html += """
                <hr>
                <h1>""" + def_sys + """<h1>
                <h3>""" + eval("DAL.Sys." + def_sys).__doc__.replace('\n', '<br>') + """<h3>
                        """

        html += """
        	</body>
        </html>
            """
    except Exception ,e:
        html = """
<html>
    <body>
    访问错误
    </body>
</html>
        """
    # print html
    return html